<template>
  <div class="group">
    <h4>团购管理</h4>

    <div class="search">
      <p>
        搜索：<input
          type="text"
          placeholder="团购搜索"
          v-model="search"
        /><button @click="btnss">搜索</button>
      </p>
      <p>状态：</p>
      <el-select v-model="value" placeholder="请选择" @change="changeselect">
        <el-option label="已开团" value="已开团"> </el-option>
        <el-option label="未开团" value="未开团"> </el-option>
      </el-select>
    </div>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed type="index" label="序号" width="200">
      </el-table-column>

      <el-table-column prop="img" label="图片" width="200"> </el-table-column>

      <el-table-column prop="buildname" label="楼盘名称" width="200">
      </el-table-column>

      <el-table-column prop="address" label="楼盘地址" width="300">
      </el-table-column>

      <el-table-column prop="name" label="发起人" width="200">
      </el-table-column>

      <el-table-column prop="time" label="起始时间" width="200">
      </el-table-column>

      <el-table-column prop="state" label="状态" width="200"> </el-table-column>

      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="del(scope)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      search: "",
      pageIndex: 1,
      pageSize: 5,
      currentPage4: 1,
      total: null,
      value: "",
    };
  },

  methods: {
    //分页
    gorup(pageIndex, pageSize) {
      this.$http
        .post("/api/getList", {
          pageIndex: pageIndex,
          pageSize: pageSize,
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data.data;
          this.total = res.data.total;
        });
    },

    handleSizeChange(val) {
      this.pageSize = val;
      this.gorup(this.pageIndex, this.pageSize);
    },

    handleCurrentChange(val) {
      this.pageIndex = val;
      this.gorup(this.pageIndex, this.pageSize);
    },
    //状态筛选
    changeselect() {
      console.log(this.value);
      this.$http
        .post("/api/selectState", {
          state: this.value,
        })
        .then((res) => {
          if (res.data.code === 1) {
            this.$message.success(res.data.message);
            this.tableData = res.data.data;
          }
        });
    },

    //删除
    del(scope) {
      console.log(scope.row.id);
      this.$http.post("/api/delete", { id: scope.row.id }).then((res) => {
        console.log(res);
        if (res.data.code === 1) {
          this.$message.success("删除成功");
          this.gorup(this.pageIndex, this.pageSize);
        }
      });
    },

    //搜索
    btnss() {
      this.$http
        .post("/api/searchTeam", {
          keyword: this.search,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code === 1) {
            this.tableData = res.data.data;
            this.$message.success("搜索成功");
          }
        });
    },
  },

  created() {
    this.gorup(this.pageIndex, this.pageSize);
  },
};
</script>

<style>
h4{
  width: 100%;
  height: 50px;
  line-height: 50px;
  background: #e6e6e6;
}
.cell {
  text-align: center;
}
.search {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
}
</style>